package com.xmcowell.sportpacemaster.config;

import android.content.Context;

import com.xmcowell.sportpacemaster.utils.PreferencesUtils;

/**
 * Created by fanyingmao on 16/12/22.
 */

public class Contents {
    public static final int WHAT_TIME_UI = 213;//计时器通知
    public static final int WHAT_TIME_STAR = 214;//跑步机正式开始跑步
    public static final int WHAT_TIME_STOP = 215;//跑步机完全停止运行

    public static final int MAIN_END = 218;
    public static final int MAIN_PAUSE = 219;

    public static final int IS_RUN = 666;
    public static final int HEART = 665;
    public static final int SHOW = 667;
    public static final int USB = 669;

    public static final int MAX_PUBLIC = 220;
    public static final int MAX_EGLISH = 120;
    public static final String DEFAULT_USERID = "defaul_userID";
    public static final String MAIN_BROADCAST = "mainBroadcast";
    public static final String Serial_Broadcast = "Serial_Broadcast";
    public static final String MUSIC_BROADCAST = "MusicBroadcast";
    public static int type = 0;//0公制 1英制
    public static String UNITS = "units";//单位,true为公制，false为英制
    private static String filePath;

    public static Type SPORT_TYPE = Type.PM930;//跑步机类型 810,820,930,940
    public static Type1 SPORT_TYPE2 = Type1.PM740;//椭圆车类型 700,730,740
    public static String IS_LOGIN = "is_login";
    public static String LOGIN_DATE = "login_date";//登录的时间点
    public static String QR_DEVICE_ID = "qr_device_id";
    public static final int TIME_THREAD_REFLASH = 888;

    public static String IS_Ch = "is_chiese"; // 是否中文

    public static String IMEI;

    public static void init(Context m) {
        filePath = m.getFilesDir().getAbsolutePath() + "/";
    }

    public static final boolean isBicycle = false;
    public static final boolean isTTYS3 = true;

    public static boolean getUnit(Context context) {
        return PreferencesUtils.getBooleanFromSPMap(context, Contents.UNITS);
    }

    public static int getMinSpeed(boolean unit) {
        if (Contents.isBicycle) {
            return 0;
        }
        if (unit) {
            return 8;
        } else {
            return 5;
        }
    }

    public static int getMaxSpeed(boolean unit) {
        if (Contents.isBicycle) {
            return getBicycleMaxSpeed(unit);
        } else {
            return getRunnerMaxSpeed(unit);
        }
    }

    private static int getBicycleMaxSpeed(boolean unit) {
        int mp = 200;
        if (unit) {
            switch (Contents.SPORT_TYPE2) {
                case PM700:

                    break;
            }
        } else {

        }
        return mp;
    }

    private static int getRunnerMaxSpeed(boolean unit) {
        int mp = 220;
        if (unit) {
            switch (Contents.SPORT_TYPE) {
                case PM810:
                    mp = 192;
                    break;
                case PM820:
                    mp = 192;
                    break;
                case PM930:
                    mp = 224;
                    break;
                case PM940:
                    mp = 256;
                    break;
            }
        } else {
            switch (Contents.SPORT_TYPE) {
                case PM810:
                    mp = 120;
                    break;
                case PM820:
                    mp = 120;
                    break;
                case PM930:
                    mp = 140;
                    break;
                case PM940:
                    mp = 160;
                    break;
            }
        }
        return mp;
    }

    /**
     * 获取跑步机首页坡度刻度盘的值
     * 不同型号的跑步机取值范围不同
     *
     * @return
     */
    public static int getMainSlope(String type, int slope) {
        if (type.equals("add")) {
            slope++;
            //增加
            if (Contents.SPORT_TYPE.equals(Type.PM810)) {
                //810最大值不能超过15
                if (slope > 15) {
                    return 15;
                } else {
                    return slope;
                }
            } else if (Contents.SPORT_TYPE.equals(Type.PM820)) {
                //820最大值不能超过18
                if (slope > 18) {
                    return 18;
                } else {
                    return slope;
                }
            } else if (Contents.SPORT_TYPE.equals(Type.PM930)) {
                //930最大值不能超过18
                if (slope > 18) {
                    return 18;
                } else {
                    return slope;
                }
            } else {
                //940最大值不能超过21
                if (slope > 21) {
                    return 21;
                } else {
                    return slope;
                }
            }
        } else {
            //减少
            slope--;
            if (slope < 0) {
                slope = 0;
            }
            return slope;
        }
    }

    /**
     * 获取跑步机首页速度刻度盘的值
     * 不同型号的跑步机取值范围不同
     *
     * @return
     */
    public static int getMainSleep(Context context, String type, int speed) {
        if (type.equals("add")) {
            speed = speed + 10;
            //增加
            if (Contents.getUnit(context)) {
                //公制
                if (Contents.SPORT_TYPE.equals(Type.PM810)) {
                    //810最大值不能超过19.2
                    if (speed > 192) {
                        return 192;
                    } else {
                        return speed;
                    }
                } else if (Contents.SPORT_TYPE.equals(Type.PM820)) {
                    //820最大值不能超过19.2
                    if (speed > 192) {
                        return 192;
                    } else {
                        return speed;
                    }
                } else if (Contents.SPORT_TYPE.equals(Type.PM930)) {
                    //930最大值不能超过22.4
                    if (speed > 224) {
                        return 224;
                    } else {
                        return speed;
                    }
                } else {
                    //940最大值不能超过25.6
                    if (speed > 256) {
                        return 256;
                    } else {
                        return speed;
                    }
                }
            } else {
                //英制
                if (Contents.SPORT_TYPE.equals(Type.PM810)) {
                    //810最大值不能超过12.0
                    if (speed > 120) {
                        return 120;
                    } else {
                        return speed;
                    }
                } else if (Contents.SPORT_TYPE.equals(Type.PM820)) {
                    //820最大值不能超过12.0
                    if (speed > 120) {
                        return 120;
                    } else {
                        return speed;
                    }
                } else if (Contents.SPORT_TYPE.equals(Type.PM930)) {
                    //930最大值不能超过14.0
                    if (speed > 140) {
                        return 140;
                    } else {
                        return speed;
                    }
                } else {
                    //940最大值不能超过16.0
                    if (speed > 160) {
                        return 160;
                    } else {
                        return speed;
                    }
                }
            }
        } else {
            //减少
            speed = speed - 10;
            if (Contents.getUnit(context)) {
                //公制,最小值不能低于0.8
                if (speed < 8) {
                    return 8;
                } else {
                    return speed;
                }
            } else {
                //英制，最小值不能低于0.5
                if (speed < 5) {
                    return 5;
                } else {
                    return speed;
                }
            }
        }
    }
}

